/**
 * Created by Dell on 2016/11/7.
 */

    // 全局常用资源
    var RainClassIcon = {
        blueIcon: L.icon({
            iconUrl: '../../source/images/rain_icon1_03.png', // 0-30
            iconSize: [14, 14] // 图标尺寸
        }),
            yellowIcon: L.icon({
            iconUrl: '../../source/images/rain_icon2_03.png', // 30-50
            iconSize: [14, 14] // 图标尺寸
        }),
            orangeIcon: L.icon({
            iconUrl: './source/images/house.png', // 50-80
            iconSize: [18, 18] // 图标尺寸
        }),
            purpleIcon: L.icon({
            iconUrl: '../../source/images/rain_icon4_03.png', // 80-100
            iconSize: [14, 14] // 图标尺寸
        }),
            redIcon: L.icon({
            iconUrl: './source/images/house_active.gif', // 100以上
            iconSize: [90, 90] // 图标尺寸
        })
    };
{
    var myIcon = {
        greed:L.icon({
            iconUrl: '../images/house.png',
            iconSize: [16,16]
        }),
        red:L.icon({
            iconUrl: '../images/house_red.png',
            iconSize: [16,16]
        })
    }
}

     // 标注显示级别
　　 var ShowNoteLevel = 8;

　    // 地图信息基类
    L.Class.FloodInfo = L.Class.extend({

        _jsonData:null,     // 地图数据
        _map:null,          // 地图引用
        _pointLayer:null,   //点图层
        _legendLayer:null,  // 图例图层
        _isVisible:false,   // 图层是否可见
        _CenterPoint:null,  // 地图中心点
        _haveInit:false,
        _ShowNoteLevle:ShowNoteLevel,   //当等级大于4时显示
        // 查看当前图层是否可见
        isVisible:function(){
            return this._isVisible;
        },

        // 图层缩放时
        _mapZoomend: function() {
            // 图标标注的显示与隐藏
            {

                if (this.getZoom() >= this._ShowNoteLevle) {
                    this._curLayer.eachLayer(function (layer) {
                        layer.openTooltip();
                        layer.on("mouseout", function () {
                            this.openTooltip();
                        });
                    });
                }
                else {
                    this._curLayer.eachLayer(function (layer) {
                        layer.closeTooltip();
                        layer.on("mouseout", function () {
                            this.closeTooltip()
                        });
                    });
                }
            }
        },

        // 显示图层
        showLayer : function () {
            this._map._curLayer = this._pointLayer;
            //this._map.on("zoomend",this._mapZoomend);
            this._map.fire("zoomend");
            if (this._isVisible) return;
            this._map.addLayer(this._pointLayer);//地图站点显示
            if(this._CenterPoint!=null) this._map.panTo(this._CenterPoint);
            if(this._legendLayer!=null)this._legendLayer.onShow(this._map);// 图例显示
            this._isVisible = true;

        },

        // 隐藏图层
        hiddenLayer:function () {
            this._map.fire("zoomend");
            if (!this._isVisible) return;
            this._map.removeLayer(this._pointLayer);// 地图站点隐藏
            if(this._legendLayer!=null)this._legendLayer.onHidden(this._map);// 图例隐藏
            this._isVisible = false;
        },
        //初始化
        init : function (map,layerlegend) {
            this._haveInit = true;
            if(arguments.length==0) {
                map = null;
                layerlegend = null;
            }
            else if(arguments.length==1) {
                layerlegend = null;
            }
            this._map = map;
            // 加入点图层
            this._pointLayer = new L.LayerGroup();
            if(this._map!=null) this._pointLayer.addTo(this._map);
            // 加入图例图层
            this._legendLayer = layerlegend;
            if(this._map!=null&&this._legendLayer!=null) this._legendLayer.addTo(this._map);

            this._isVisible = true;
            this._CenterPoint = null;
            this._map._ShowNoteLevle = this._ShowNoteLevle;
            this._map._mapZoomend = this._mapZoomend;
            this._map.on("zoomend",this._mapZoomend);
            return this;
        },

        haveInit:function(){
            return this._haveInit;
        },

        //清空地图上的站点信息
        ClearStationInfo:function(){
            if(this._pointLayer!=null)
                this._pointLayer.clearLayers();
    }
});


var locationLevel = 18;
var ImgIcon;
var newPointLayer = new L.LayerGroup();

var setview = function(lttd,lgtd){
    myMap.setView([lttd,lgtd],locationLevel);
    //var newIcon =RainClassIcon.redIcon;
    //console.log(newIcon)
    //L.marker([lttd, lgtd], {
    //    icon:newIcon,
    //    draggable: false        // 使图标可拖拽
    //}).add(newPointLayer);
    //console.log(123123)
}

var locview = function(lttd,lgtd){
    console.log(lttd)
    console.log(lgtd)
    myMap.setView([lttd,lgtd],16);
    //var newIcon =RainClassIcon.redIcon;
    //console.log(newIcon)
    //L.marker([lttd, lgtd], {
    //    icon:newIcon,
    //    draggable: false        // 使图标可拖拽
    //}).add(newPointLayer);
    //console.log(123123)
}


var StationInfo = L.Class.FloodInfo.extend({
    // 放入属性信息
});

var StationLayer
//绘制站点到地图上
StationInfo.prototype.DrawStationInfo = function (stationList) {
    for (var i in stationList) {
        var ev = stationList[i];
        ImgIcon = RainClassIcon.orangeIcon;
        //console.log(ev)
        var id = ev.ID;
        StationLayer = L.marker([ev.lttd, ev.lgtd], {
                icon:ImgIcon,
                draggable: false        // 使图标可拖拽
            })
            .bindTooltip("<div class='tips'><h3 ><b>"+ev.name +"</b></h3>" + ev.Address+"<p>"+ev.SYDW_Name+"</p></div>",{offset: L.point(0, -10),direction:"top"})
            .addTo(this._pointLayer);
        StationLayer.info = ev;
        StationLayer.on("click",ShowPLChart);
    }
};

var curStationInfo = null;
var stationPLpopup = L.popup();
// 显示过程线函数
var ShowPLChart = function()
{
    curStationInfo = this.info;
    //console.log(curStationInfo.ID)
    $('.cardlist').hide();
    $('.detailsBox').fadeIn();
    detailsClick(curStationInfo.ID);
    stationPLpopup.setLatLng([this.info.lttd,this.info.lgtd]);
    //stationPLpopup.setContent("<div style='height:400px;width:300px'><iframe src='detailInfo.html' height='400' width='300' frameborder='0'></iframe></div>");
    //stationPLpopup.openOn(this._map);
};

var ShowDetailInfo = function(lttd,lgtd,map,id)
{
    curStationInfo = this.info;
    stationPLpopup.setLatLng([lttd,lgtd]);
    var url = "http://10.41.216.74:7005/FA/Proxy?function=geteditpage&componame=FA_CARD_INONE&condition= FA_CARD.CARD_ID="+id+ "&fieldvalue=071999002000000233&styleCode=FA_CARD_000000005";
    //console.log(url)
    stationPLpopup.setContent("<div style='height:500px;width:800px'><iframe src=" + url + "  height='500' width='800' frameborder='0'></iframe></div>");
    stationPLpopup.openOn(map);
};

var MapCenter = function(min,max){
    myMap.fitBounds([min,max]);
    //console.log(myMap.getZoom());
    if(myMap.getZoom()>18){
        myMap.setZoom(18)
    }
};


var setCenter = function(point){
    myMap.center(point);
    //console.log(myMap.getZoom());
    if(myMap.getZoom()>18){
        myMap.setZoom(18)
    }
};

var highLightLayer = new L.layerGroup();













